package org.order.server;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import org.example.common.LogisticsService;
import org.example.common.OrderService;
import org.example.common.ProductService;
import org.example.model.Logistics;
import org.example.model.Order;
import org.example.model.Product;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Reference
    private ProductService productService;
    @Reference
    private LogisticsService logisticsService;

    public Order getOrderById(Long id) {
        Order order = new Order();
        order.setId(id);
        order.setAmount(new BigDecimal("10000.00"));
        List<Product> products = new ArrayList<Product>();
        Product product = null;
        for (int i =0; i <3; i++){
            product = productService.getProductById(i+ 1L);
            if (null != product){
                products.add(product);
            }
        }
        List<Logistics> logisticsList = logisticsService.getLogisticsById(id);
        order.setLogisticsList(logisticsList);
        order.setProductList(products);
        return order;
    }
}
